<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>  
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/resources/js/themes/default/easyui.css" />
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/resources/js/themes/icon.css" />
    <script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/jquery-1.8.3.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="<%=request.getContextPath()%>/resources/js/extEasyUI.js"></script>
	<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/resources/css/extEasyUIIcon.css" />
  	<script type="text/javascript">
        
        function formatEnable(v,r){
        	return v ? "是" : "否";
        }
        
        function newUser(){
        	parent.$.modalDialog({
				title : '创建用户',
				width : 440,
				height : 220,
				href : '<%=request.getContextPath() %>/user/addUser',
				buttons:[{
					text : '保存',
					iconCls:'icon-ok',
					handler:function(){
						parent.$.modalDialog.handler.userGrid = jQuery("#userTab"); 
						parent.$.modalDialog.handler.find('#form').submit();
					}
				},{
					text : '取消',
					iconCls:'icon-cancel',
					handler:function(){
						parent.$.modalDialog.handler.dialog('close');
					}
				}]
			});
        }
        
        function editUser(){
        	var selectNode = jQuery("#userTab").datagrid("getSelected");
			
			if (selectNode == null){
				parent.$.messager.alert('提示', '请点击一行选择您要修改的用户。', 'info');
				return false;
			}
			
			parent.$.modalDialog({
				title : '修改用户',
				width : 440,
				height : 180,
				href : '<%=request.getContextPath() %>/user/editUser?username='+selectNode.username,
				buttons:[{
					text : '保存',
					iconCls:'icon-ok',
					handler:function(){
						parent.$.modalDialog.handler.userGrid = jQuery("#userTab"); 
						parent.$.modalDialog.handler.find('#form').submit();
					}
				},{
					text : '取消',
					iconCls:'icon-cancel',
					handler:function(){
						parent.$.modalDialog.handler.dialog('close');
					}
				}]
			});
        }
        
        function deleteUser(){
        	var selectNode = jQuery("#userTab").datagrid("getSelected");
			
			if (selectNode == null){
				parent.$.messager.alert('提示', '请点击一行选择您要删除的用户。', 'info');
				return false;
			}
			
			parent.$.messager.confirm('询问', '您是否要删除当前用户？', function(b) {
				if (b) {
					openProgress();
					$.post('<%=request.getContextPath() %>/user/delUser', {
						userid : selectNode.userid
					}, function(data) {
						parent.$.messager.progress('close');
						
						if (data.result) {
							parent.$.messager.alert('提示', '删除成功', 'info');
							jQuery("#userTab").datagrid('reload');
						}
					}, 'JSON');
				}
			});
        }
        
    </script>
  </head>
  
  <body>
    <table class="easyui-datagrid" title="用户列表" 
    		id="userTab"
    		data-options="
    			rownumbers:'true',
    			pagination:'true',
    			toolbar:'#toolbar',
    			singleSelect:'true',
    			url:'<%=request.getContextPath() %>/user/getUserList'
    		"
    		>
        <thead>
            <tr>
<%--            	<th data-options="field:'userid',checkbox:true"></th>--%>
                <th data-options="field:'username',align:'center',sortable:true" width='200'>用户名</th>
                <th data-options="field:'nickname',align:'center',sortable:true" width='200'>昵称</th>
                <th data-options="field:'enable',align:'center',sortable:true,formatter:formatEnable">是否启用</th>
            </tr>
        </thead>
    </table>
 	<div id="toolbar">
 		<shiro:hasPermission name="User:add">  
        	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon_user_add" plain="true" onclick="newUser()">创建用户</a>
        </shiro:hasPermission>
        <shiro:hasPermission name="User:edit">  
        	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon_user_edit" plain="true" onclick="editUser()">修改用户</a>
        </shiro:hasPermission>
        <shiro:hasPermission name="User:delete">  
        	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon_user_delete" plain="true" onclick="deleteUser()">删除用户</a>
        </shiro:hasPermission>
        <a onclick="jQuery('#userTab').datagrid('reload');" href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon_refresh'">刷新</a>
    </div>
  </body>
</html>
